package com.weipeep.oss.config;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.qiniu.common.Zone;
import com.weipeep.common.domain.ConfigDO;
import com.weipeep.common.service.ConfigService;
import com.weipeep.oss.sdk.AliOSSService;
import com.weipeep.oss.sdk.OSSConfig;
import com.weipeep.oss.sdk.QiNiuOSSService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableCaching
public class OSS {
    
    @Autowired
    private ConfigService configService;
    
    @Bean
    public QiNiuOSSService qiNiuOSS() {
        /**
         * {
         * "AccessKey" : "HJqnduDDp_7jjBcyaTAhV8KztAYREiYp5uHovJzr",
         * "SecretKey" : "edTmWiwvCMf1KuPw_Grh2nvbjLCU_JO32I3T0uvg",
         * "bucket" : "weipeep",
         * "AccessUrl" : "http://p8jnyhp6s.bkt.clouddn.com/"
         * }
         */
        String ak = "HJqnduDDp_7jjBcyaTAhV8KztAYREiYp5uHovJzr";
        String sk = "edTmWiwvCMf1KuPw_Grh2nvbjLCU_JO32I3T0uvg";
        String bucket = "01bearing";
        String accessUrl = "http://p8s0khu9j.bkt.clouddn.com/";
        
        OSSConfig ossConfig = new OSSConfig();
        ossConfig.setQiNiuAccessKey(ak);
        ossConfig.setQiNiuSecretKey(sk);
        ossConfig.setQiNiuBucket(bucket);
        ossConfig.setQiNiuAccessURL(accessUrl);
        
        return new QiNiuOSSService(ossConfig, Zone.zone1(), bucket, ak, sk);
    }
    @Bean
    public AliOSSService aliOSSService() {
        /**
         * {
         * "endpoint" : "http://oss-cn-beijing.aliyuncs.com",
         * "accessKeyId" : "LTAIhdLUAeQIcTzf",
         * "accessKeySecret" : "lLwcR7XShJpAwhxPMBfNmOfqvnaLGh",
         * "accessUrl" : "http://wepeep.oss-cn-beijing.aliyuncs.com",
         * "bucketName":"wepeep"
         * }
         */
        String endpoint ="http://oss-cn-beijing.aliyuncs.com";
        String accessKeyId = "LTAIhdLUAeQIcTzf";
        String accessKeySecret = "lLwcR7XShJpAwhxPMBfNmOfqvnaLGh";
        String accessUrl = "http://wepeep.oss-cn-beijing.aliyuncs.com";
        String bucketName = "wepeep";
        return new AliOSSService( endpoint, accessKeyId, accessKeySecret,accessUrl,bucketName);
    }
}
